package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Tag;
import com.hs.sfzy.service.TagService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TagController
 * @Description TODO
 * @Author wangzhihao
 * @Date 2025年08月13日 11:25
 * @Version 1.0
 */
@RestController
@RequestMapping("Tag")
public class TagController {
    @Autowired
    private TagService tagService;
    @PostMapping
    public R addTag(@RequestBody Tag tag) {
        int i = tagService.insertTag(tag);
        if (i > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @GetMapping("{id}")
    public R getTag(@PathVariable("id") int id) {
        Tag tag = tagService.selectTagById(id);
        return R.ok(tag);
    }
    @GetMapping("page")
    public R getTags(@RequestParam(required = false,defaultValue ="1") int pageNum,
                     @RequestParam(required = false,defaultValue ="3") int pageSize){
        PageInfo<Tag> tagPageInfo = tagService.selectTagByPage(pageNum, pageSize);
        return R.ok(tagPageInfo);
    }
}
